package main

import "fmt"

func main() {
	//initMap()
	//printMap()
	complexMap()
}

func initMap() {
	// 方式1
	myMap1 := make(map[string]string, 4)
	myMap1["1"] = "test1"
	myMap1["2"] = "test2"
	myMap1["3"] = "test3"
	myMap1["4"] = "test4"
	fmt.Println(myMap1)

	// 方式2
	myMap2 := map[int]string{
		11: "11",
		22: "22",
		33: "33",
	}
	fmt.Println(myMap2)

	delete(myMap1, "1") // 根据KEY删除元素
	fmt.Println(myMap1)

	map2Val := myMap2[11]
	fmt.Println(map2Val) // 输出指定key的value

}

func printMap() {
	// 方式1
	myMap1 := make(map[string]string, 4)
	myMap1["1"] = "test1"
	myMap1["2"] = "test2"
	myMap1["3"] = "test3"
	myMap1["4"] = "test4"

	for key, val := range myMap1 {
		fmt.Println(key, val)
	}
}

// 这是一个复杂的map， map的key是string， value还是一个map，
func complexMap() {
	compMap := make(map[string]map[int]string)
	// 一年一班有三个人，对应的学号和姓名
	compMap["一年一班"] = make(map[int]string, 3)
	compMap["一年一班"][2024001001] = "张三"
	compMap["一年一班"][2024001002] = "李四"

	compMap["一年二班"] = make(map[int]string, 3)
	compMap["一年二班"][2024002001] = "zhangsan"
	compMap["一年二班"][2024002002] = "lisi"

	for classKey, studentMap := range compMap {
		fmt.Printf("----------------当前班级 : %v ------------- \n", classKey)
		for stuKey, stuName := range studentMap {
			fmt.Printf("学号=%d ，姓名= %s\n", stuKey, stuName)
		}
	}
}
